<?php

namespace App\Store\Models\Sysset;

use App\Common\Services\Common;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use App\Common\Services\Store\Common as StoreCommon;

class GoodsSendpoints extends Model
{
    protected $table = 'site_sysset_goods_sendpoints';
    public $timestamps = false;
    protected $primaryKey = 'id';
    protected $guarded = ['_token'];

    /**
     *获取列表 
     */
    public static function getList(Request $request)
    {

        $cp_id = StoreCommon::getCurrentAccountCompanyId($request);
        $query = self::where(['cp_id' => $cp_id, 'is_del' => 1])->orderBy('create_at', 'desc');


        $isgetall = intval($request->isgetall) ?? 0;

        $store_id = intval($request->store_id);
        if ($store_id>0) {
            $query->where('store_id', $store_id);
        }

        $goods_category_id = intval($request->goods_category_id);
        if ($goods_category_id>0) {
            $query->where('goods_category_id', $goods_category_id);
        }

        $type = intval($request->type);
        if ($type>0) {
            $query->where('type', $type);
        }

        if ($isgetall == 0) {
            $limit = $request->limit ?? 10;
            $list = $query->paginate($limit)->toArray();
            return Common::paginateDataToArray($list);
        } else {
            $list = $query->get()->toArray();
            return ['list' => $list];
        }
    }
}
